﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RTGS.Library.Entities.Rtgs;
using RTGS.Library.DataAccess.Rtgs;
using System.Configuration;
using RTGS.Web;
using System.Data;
using RTGS.Library.Report;

public partial class form_rtgs_clearing_sknbiform : BasePage
{
    private trntRepo trntrepo = new trntRepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);

    private stpRecordDetailORepo roleDal = new stpRecordDetailORepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
    ReportSptDetailRecordO reportDal = new ReportSptDetailRecordO(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
    private string id = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           // try
          //  {
                List<trnt> listtrnt = trntrepo.GetList();
                foreach (var item in listtrnt)
                {
                    ddlTrn.Items.Add(new ListItem(item.trn.Trim(), item.trndesc.Trim()));
                }

                ddlTrn.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));

                DataTable dt = reportDal.GetMember();

                ddlDebitParticipant.Items.Clear();
                foreach (DataRow dr in dt.Rows)
                {
                    ddlDebitParticipant.Items.Add(new ListItem(dr["accnbr"].ToString().Trim(), dr["memcde"].ToString().Trim()));
                }

                ddlDebitParticipant.Items.Insert(0, new ListItem("---pilih data--", string.Empty));

                ddlCreditParticipant.Items.Clear();
                foreach (DataRow dr in dt.Rows)
                {
                    ddlCreditParticipant.Items.Add(new ListItem(dr["accnbr"].ToString().Trim(), dr["memcde"].ToString().Trim()));
                }

                ddlCreditParticipant.Items.Insert(0, new ListItem("---pilih data--", string.Empty));

                if (ddlDebitParticipant.Items.Count > 0)
                {
                    for (int i = 0; i < ddlDebitParticipant.Items.Count; i++)
                    {
                        if (ddlDebitParticipant.Items[i].Value.ToString().Trim() == "BKCHIDJA")
                        {
                            ddlDebitParticipant.Items.FindByValue("BKCHIDJA").Selected = true;
                            break;

                        }
                    }
                }

                if (ddlCreditParticipant.Items.Count > 0)
                {
                    for (int i = 0; i < ddlCreditParticipant.Items.Count; i++)
                    {
                        if (ddlCreditParticipant.Items[i].Value.ToString().Trim() == "SKNAIDJ1")
                        {

                            ddlCreditParticipant.Items.FindByValue("SKNAIDJ1").Selected = true;
                            break;
                        }
                    }
                }

                txtDebitParticipant.Text = "BKCHIDJA";
                txtCreditParticipant.Text = "SKNAIDJ1";

                if (Context.Request.Params["sknbi"] != null)
                {
                    if (Context.Request.Params["sknbi"] == "prefundkredit")
                        ddlTransTypeCode.Items.FindByValue("300").Selected = true;

                    if (Context.Request.Params["sknbi"] == "prefunddebit")
                        ddlTransTypeCode.Items.FindByValue("310").Selected = true;

                    if (Context.Request.Params["sknbi"] == "topprefundkredit1")
                        ddlTransTypeCode.Items.FindByValue("301").Selected = true;

                    if (Context.Request.Params["sknbi"] == "topprefundkredit2")
                        ddlTransTypeCode.Items.FindByValue("302").Selected = true;

                    if (Context.Request.Params["sknbi"] == "topprefunddebit")
                        ddlTransTypeCode.Items.FindByValue("311").Selected = true;


                }

                if (Request.Params["Id"] != null)
                {
                    id = HttpUtility.HtmlEncode(Convert.ToString(Request.Params["Id"]));
                }

                if (id.Trim().Length > 0) // Edit an existing item
                {
                    stpRecordDetailO obj = roleDal.GetById(id);
                    if (obj != null)
                    {
                        hfID.Value = id.ToString();


                        if (obj.recordDetailOtrTrn != "")
                        {
                            //if (ddlTrn.Items.Count > 0)
                            //{
                            //for (int i = 0; i < ddlTrn.Items.Count; i++)
                            //{
                            //if (ddlTrn.Items[i].ToString().Trim() == obj.recordDetailOtrTrn.Trim())
                            //{

                            ddlTrn.Items.FindByText(obj.recordDetailOtrTrn).Selected = true;
                            //}
                            //}
                            //}

                            trnt data = trntrepo.GetById(obj.recordDetailOtrTrn);

                            txtTrnDesc.Text = data.trndesc;
                        }

                        //group amount
                        txtAmount.Text = obj.recordDetailOtrAmount;// Convert.ToDecimal(obj.recordDetailOtrAmount).ToString();
                        txtBussinesDay.Text = obj.recordDetailOtrValuedate;

                        //group priority
                        txtPriority.Text = obj.recordDetailOrecordPriority;

                        //group detail
                        if (obj.recordDetailOtrTransactioncode != null && obj.recordDetailOtrTransactioncode != "")
                            ddlTransTypeCode.Items.FindByValue(obj.recordDetailOtrTransactioncode).Selected = true;

                        if (obj.recordDetailOtrFrommember != null && obj.recordDetailOtrFrommember != "")
                            ddlDebitParticipant.Items.FindByValue(obj.recordDetailOtrFrommember.Trim()).Selected = true;

                        if (obj.recordDetailOtrTomember != null && obj.recordDetailOtrTomember != "")
                            ddlCreditParticipant.Items.FindByValue(obj.recordDetailOtrTomember.Trim()).Selected = true;

                        txtDebitParticipant.Text = obj.recordDetailOtrFrommember;
                        txtCreditParticipant.Text = obj.recordDetailOtrTomember;
                    }
                }
            //}
            //catch (Exception ex)
            //{
            //}

            }
        
    }
}